<?php
require_once('./class/Adherent.php');
require_once ('./class/Statistique.php');
switch (@$_GET['action']){
    default:
        echo _ADHERENT_;
    break;

    case "list":
        $adherent_array = Adherent::getAllAdherent();
        $html = '<table class="tablesorter">
        							<thead>
        								<th>'._ID_INDIVIDU_.'</th>
        								<th>'._NOM_INDIVIDU_.'</th>
        								<th>'._PRENOM_INDIVIDU_.'</th>
        								<th>'._EMAIL_ADHERENT_.'</th>
        								<th>'._FILIERE_ADHERENT_.'</th>
        								<th>'._PROMOTION_ADHERENT_.'</th>
        								<th>'._AVERAGE_COMMENT_PER_NEWS_.'</th>
        								<th>'._EDIT_.'</th>
        								<th>'._DELETE_.'</th>
        							</thead><tbody>';
        $i = 0;
        foreach($adherent_array as $a){
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
        								<td>'.$a->getIdIndividu().'</td>
        								<td>'.$a->getNom().'</td>
        								<td>'.$a->getPrenom().'</td>
        								<td>'.$a->getEmail().'</td>
        								<td>'.$a->getFiliere().'</td>
        								<td>'.$a->getPromotion().'</td>
        								<td>'.Statistique::getAverageCommentPerNews($a->getIdIndividu()).'</td>
        							<td><a href="?module=adherent&action=modify&id='.$a->getIdIndividu().'" >'._EDIT_.'</a></td>
        							<td><a href="?module=adherent&action=delete&id='.$a->getIdIndividu().'">'._DELETE_.'</td>
        						</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;

    case "modify":
        $adherent = Adherent::getAdherent($_GET['id']);
        echo $adherent->getModifyForm();
        break;

    case "doModify":
        $a = new Adherent();
        $a->setId($_POST['id_individu']);
        $a->setFiliere($_POST['filiere']);
        $a->setPromotion($_POST['promotion']);
        $a->setEmail($_POST['email']);
        $a->addOrModify();
        echo _ADHERENT_.' '._MODIFIED_;
        break;

    case "delete":
        $a = Adherent::getAdherent($_GET['id']);
        $a->delete();
        echo _ADHERENT_.' '._DELETED_;
        break;
}
?>